/*
 * yByteArray.h
 *
 *  Created on: Sep 14, 2016
 *      Author: root
 */

#ifndef BASE_NET_YBYTEARRAY_H_
#define BASE_NET_YBYTEARRAY_H_
#include <string>
class ByteArray {
public:
	ByteArray();
	ByteArray(int c);
	ByteArray(char* v, int len);
	~ByteArray();
	int readByte();
	int readShort();
	int readInt();
	long readLong();
	float readFloat();
	double readDouble();
	std::string readString();
	void writeByte(char value);
	void writeShort(short value);
	void writeInt(int value);
	void writeLong(long value);
	void writeFloat(float value);
	void writeDouble(double value);
	void writeString(std::string &value);
	void writeBytes(char* value, int len);
	int readerIndex();
	int writerIndex();
	void readerIndex(int idx);
	void writerIndex(int idx);
	char* buf;
private:
	int capacity;
	int wIndex;
	int rIndex;
	void autoFitLen(int len);
};

#endif /* BASE_NET_YBYTEARRAY_H_ */
